#pragma warning(disable:4530)

#include "osplatform.h"
#include <string.h>
#include <ctype.h>

#include "MethodTypes.h"

static SIPMethods g_Methods[MAX_METHODS] =
{
	{ACK,"ACK"},
	{BYE,"BYE"},
	{CANCEL,"CANCEL"},
	{INVITE,"INVITE"},
	{NOTIFY,"NOTIFY"},
	{OPTIONS,"OPTIONS"},
	{PUBLISH,"PUBLISH"},
	{REFER,"REFER"},
	{REGISTER,"REGISTER"},
	{SUBSCRIBE,"SUBSCRIBE"},
	{UPDATE,"UPDATE"},
	{MESSAGE,"MESSAGE"},
	{INFO,"INFO"},	
	{UNKNOWN,"UNKNOWN"}, 
};

MethodTypes GetMethodType(const char *pmethod)
{
   // note: use data to prevent copying shared data
   if(pmethod == NULL)
	   return UNKNOWN;
   for(int i=0;i<MAX_METHODS;i++)
   {
	   if(strcmp(pmethod,g_Methods[i].name) == 0)
		   return g_Methods[i].method;
   }
   return UNKNOWN;
}

const char *GetMethodName(MethodTypes mt)
{
	if(mt < 0 || mt >= UNKNOWN)
		return g_Methods[UNKNOWN].name;
	else
		return g_Methods[mt].name;
}
int strncasecmp(const char* a, const char* b, int len)
{   
   for (int i = 0; i < len; i++)
   {
      int c = tolower(a[i]) - tolower(b[i]);
      if (c) return c;
   }
   return 0;
}

